home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
COMAL
/
B-Book Series
/
(k)b4.d64
/
example12.5
< prev
next >
Wrap
Text File
|
2007-02-28
|
822b
|
38 lines
0010 DIM KEY'(100), RECNO(100), DESCR$ OF 12
0020 OPEN FILE 2,"KEYFILE",RANDOM 10
0030 FOR R:=1 TO 99 DO READ FILE 2,R,1: KEY'(R),RECNO(R)
0040 CLOSE
0050 OPEN FILE 2,"INFILE",RANDOM 19
0070 REPEAT
0080 REPEAT
0090 INPUT "WHAT IS THE SEARCH KEY (1-9999)?": SEEK
0100 UNTIL SEEK<=9999 AND SEEK>=0
0110 IF SEEK=0 THEN
0120 CLOSE
0130 STOP
0140 ELSE
0150 BINSEARCH(1,99)
0160 ENDIF
0170 UNTIL 2=1
0180 PROC BINSEARCH(LOW,TOP)
0190 FOUND:=FALSE
0200 REPEAT
0210 MID:=(LOW+TOP) DIV 2
0220 IF KEY'(MID)=SEEK THEN
0230 FOUND:=TRUE
0240 ELSE
0250 IF KEY'(MID)>SEEK THEN
0260 TOP:=MID-1
0270 ELSE
0280 LOW:=MID+1
0290 ENDIF
0300 ENDIF
0310 UNTIL FOUND OR LOW>TOP
0320 IF FOUND THEN
0330 READ FILE 2,RECNO(MID),1: NUM,DESCR$
0340 PRINT NUM;DESCR$
0350 ELSE
0360 PRINT SEEK;"NOT FOUND"
0370 ENDIF
0380 ENDPROC BINSEARCH